home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / dopus412-gpl / program / doerror.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  6KB  |  254 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "DOpus.h"
  32.  
  33. static short errcodes[36][2]={
  34.     {103,STR_NOT_ENOUGH_MEMORY},
  35.     {104,STR_PROCESS_TABLE_FULL},
  36.     {114,STR_BAD_TEMPLATE},
  37.     {115,STR_BAD_NUMBER},
  38.     {116,STR_REQUIRED_ARG_MISSING},
  39.     {117,STR_ARGUMENT_MISSING},
  40.     {118,STR_TOO_MANY_ARGUMENTS},
  41.     {119,STR_UNMATCHED_QUOTES},
  42.     {120,STR_ARG_LINE_TOO_LONG},
  43.     {121,STR_FILE_NOT_EXECUTABLE},
  44.     {122,STR_INVALID_LIBRARY},
  45.     {202,STR_OBJECT_IN_USE},
  46.     {203,STR_OBJECT_EXISTS},
  47.     {204,STR_DIR_NOT_FOUND},
  48.     {205,STR_OBJECT_NOT_FOUND},
  49.     {206,STR_INVALID_WINDOW},
  50.     {209,STR_UNKNOWN_PACKET},
  51.     {210,STR_OBJECT_NAME_INVALID},
  52.     {211,STR_INVALID_LOCK},
  53.     {212,STR_OBJECT_BAD_TYPE},
  54.     {213,STR_DISK_NOT_VALIDATED},
  55.     {214,STR_DISK_WRITE_PROTECTED},
  56.     {215,STR_RENAME_DEVICES_ATTEMPTED},
  57.     {216,STR_DIRECTORY_NOT_EMPTY},
  58.     {217,STR_TOO_MANY_LEVELS},
  59.     {218,STR_DEVICE_NOT_MOUNTED},
  60.     {219,STR_SEEK_ERROR},
  61.     {220,STR_COMMENT_TOO_LONG},
  62.     {221,STR_DISK_FULL},
  63.     {222,STR_OBJECT_DELETE_PROTECTED},
  64.     {223,STR_OBJECT_WRITE_PROTECTED},
  65.     {224,STR_OBJECT_READ_PROTECTED},
  66.     {225,STR_NOT_VALID_DOS_DISK},
  67.     {226,STR_DEVICE_NOT_MOUNTED},
  68.     {232,STR_NO_MORE_ENTRIES},
  69.     {233,STR_OBJECT_IS_SOFT_LINK}};
  70.  
  71. doerror(err)
  72. int err;
  73. {
  74.     char buf[80];
  75.  
  76.     if (err && geterrorstring(buf,err)) {
  77.         dostatustext(buf);
  78.         rexx_result_code=err;
  79.         return(1);
  80.     }
  81.     return(0);
  82. }
  83.  
  84. geterrorstring(buf,err)
  85. char *buf;
  86. int err;
  87. {
  88.     int a;
  89.  
  90.     for (a=0;a<36;a++) {
  91.         if (errcodes[a][0]==err) {
  92.             lsprintf(buf,globstring[STR_DOS_ERROR_CODE],err);
  93.             strcat(buf," - ");
  94.             strcat(buf,globstring[errcodes[a][1]]);    
  95.             return(1);
  96.         }
  97.     }
  98.     return(0);
  99. }
  100.  
  101. void dostatustext(text)
  102. char *text;
  103. {
  104.     int x,len,l;
  105.     struct RastPort *r;
  106.  
  107.     if (status_iconified) {
  108.         if (status_flags&STATUS_ISINBUTTONS) iconstatustext(text,1);
  109.         return;
  110.     }
  111.     if (status_flags&STATUS_FROMHOTKEY) return;
  112.     strcpy(str_last_statustext,text);
  113.     if (scrdata_status_height>0) {
  114.         r=main_rp;
  115.         SetDrawModes(r,config->statusfg,config->statusbg,JAM2);
  116.         SetFont(r,scr_font[FONT_STATUS]);
  117.         len=0;
  118.         l=dotextlength(r,text,&len,scrdata_status_width-4);
  119.         switch (scrdata_statustext_pos) {
  120.             case TOPTEXT_CENTER: x=((scrdata_status_width-l)/2)+scrdata_status_xpos; break;
  121.             case TOPTEXT_LEFT: x=scrdata_status_xpos+2; break;
  122.             case TOPTEXT_RIGHT: x=(scrdata_status_width-l)+scrdata_status_xpos; break;
  123.         }
  124.         if (x<scrdata_status_xpos) x=scrdata_status_xpos;
  125.         Move(r,x,scr_font[FONT_STATUS]->tf_Baseline+2+scrdata_yoffset);
  126.         Text(r,text,len);
  127.         SetFont(r,scr_font[FONT_GENERAL]);
  128.         SetAPen(r,screen_pens[config->statusbg].pen);
  129.         if (x>scrdata_status_xpos)
  130.             RectFill(r,
  131.                 scrdata_status_xpos,scrdata_status_ypos+1,
  132.                 x-1,scrdata_yoffset+scrdata_status_height-2);
  133.         if (x+l<scrdata_status_xpos+scrdata_status_width)
  134.             RectFill(r,
  135.                 x+l,scrdata_status_ypos+1,
  136.                 scrdata_status_xpos+scrdata_status_width-1,scrdata_yoffset+scrdata_status_height-2);
  137.     }
  138.     else {
  139.         if (status_publicscreen) SetWindowTitles(Window,str_last_statustext,(char *)-1);
  140.         else {
  141.             SetWindowTitles(Window,(char *)-1,str_last_statustext);
  142.             if (IntuitionBase->ActiveScreen==MainScreen &&
  143.                 IntuitionBase->ActiveWindow!=Window)
  144.                 SetWindowTitles(IntuitionBase->ActiveWindow,(char *)-1,str_last_statustext);
  145.             MainScreen->DefaultTitle=str_last_statustext;
  146.         }
  147.     }
  148. }
  149.  
  150. void okay()
  151. {
  152.     dostatustext(globstring[STR_OKAY_TITLE]);
  153.     rexx_result_code=0;
  154. }
  155.  
  156. void myabort()
  157. {
  158.     dostatustext(globstring[STR_ABORTED]);
  159.     status_justabort=1; status_haveaborted=0;
  160.     rexx_result_code=-1;
  161. }
  162.  
  163. void dofilename(text)
  164. char *text;
  165. {
  166.     int a,len,pos,old;
  167.     struct TextFont *font;
  168.  
  169.     old=scrdata_statustext_pos;
  170.     len=a=strlen(text);
  171.     if (scrdata_status_height>0) font=scr_font[FONT_STATUS];
  172.     else font=Window->WScreen->RastPort.Font;
  173.     
  174.     gettextlength(font,text,&len,scrdata_status_width);
  175.     pos=a-len;
  176.     if (config->dynamicflags&UPDATE_LEFTJUSTIFY) {
  177.         scrdata_statustext_pos=TOPTEXT_LEFT;
  178.         if (pos>0) {
  179.             for (a=pos;a<len;a++) {
  180.                 if (text[a]=='/' || text[a]==':') {
  181.                     while (text[a]=='/' || text[a]==':') ++a;
  182.                     break;
  183.                 }
  184.             }
  185.             pos=a;
  186.         }
  187.     }
  188.     else scrdata_statustext_pos=TOPTEXT_CENTER;
  189.     dostatustext(&text[pos]);
  190.     scrdata_statustext_pos=old;
  191. }
  192.  
  193. void geterrorhelp(st)
  194. int st;
  195. {
  196.     char buf[80],buf2[30];
  197.     int err;
  198.  
  199.     if (!st) {
  200.         buf[0]=0;
  201.         if (!(whatsit(globstring[STR_ENTER_DOS_ERROR_CODE],4,buf,NULL)) || buf[0]==0)
  202.             return;
  203.         err=atoi(buf);
  204.     }
  205.     else err=atoi(rexx_args[0]);
  206.     if (doerror(err)) {
  207.         lsprintf(buf2,"!%ld",err);
  208.         dohelp(buf2,NULL,0,0,globstring[STR_NO_HELP_FOR_ERROR]);
  209.     }
  210.     else dostatustext(globstring[STR_NO_HELP_FOR_ERROR]);
  211. }
  212.  
  213. checkerror(action,name,err)
  214. char *action,*name;
  215. int err;
  216. {
  217.     char buf[300],buf2[200];
  218.     int a=1,skip=1,erhelp=1;
  219.  
  220.     if (err<0) {
  221.         err=-err;
  222.         skip=0;
  223.     }
  224.     if (!(config->errorflags&ERROR_ENABLE_OPUS)) return((skip)?2:3);
  225.  
  226.     if (geterrorstring(buf2,err))
  227.         lsprintf(buf,globstring[STR_ERROR_OCCURED],action,name,buf2);
  228.     else {
  229.         lsprintf(buf,globstring[STR_ERROR_OCCURED],action,name,"");
  230.         erhelp=0;
  231.     }
  232.  
  233.     FOREVER {
  234.         a=simplerequest(buf,
  235.             globstring[STR_TRY_AGAIN], /* 1 */
  236.             globstring[STR_ABORT],     /* 0 */
  237.             (skip)?globstring[STR_SKIP]:NULL,  /* 2 */
  238.             (dopus_firsthelp && erhelp)?globstring[STR_ERROR_ERROR_HELP]:NULL,  /* 2 or 3 */
  239.             NULL);
  240.  
  241.         if ((skip && a==3) || (!skip && a==2)) {
  242.             char helpbuf[20];
  243.  
  244.             lsprintf(helpbuf,"!%ld",err);
  245.             dohelp(helpbuf,NULL,0,0,globstring[STR_NO_HELP_FOR_ERROR]);
  246.             busy();
  247.         }
  248.         else break;
  249.     }
  250.  
  251.     if (a==0) return(3);
  252.     return(a);
  253. }
  254.